package main

import (
	"encoding/json"
	"fmt"
	"go-web-learning/src/04_gorm/db"
)

var DB = db.DB

func main() {
	enumType()
}

func jsonType() {
	DB.AutoMigrate(&db.AuthModel{})

	//DB.Create(&db.AuthModel{
	//	Name: "kunkun",
	//	Info: db.Info{
	//		Address: "上海",
	//		Age:     26,
	//		Like:    "CTRL",
	//	},
	//})

	var auth db.AuthModel
	DB.Take(&auth)
	fmt.Println(auth)
}

func arrayType() {
	DB.AutoMigrate(&db.HostModel{})
	//
	//DB.Create(&db.HostModel{
	//	IP:   "127.0.0.1",
	//	Post: db.Array{"80", "443", "3306"},
	//})

	var host db.HostModel
	DB.Take(&host)
	fmt.Println(host)
}

func enumType() {
	DB.AutoMigrate(&db.HostModel{})

	//DB.Create(&db.HostModel{
	//	IP:     "127.0.0.1",
	//	Status: db.Running,
	//	Post:   db.Array{"81"},
	//})

	var host []db.HostModel
	DB.Find(&host)
	fmt.Println(host)
	data, _ := json.Marshal(host)
	fmt.Println(string(data))
}
